package com.weng.cloud.service8881.async.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

/**
 * @Author: weng
 * @Date: 2022/4/26
 * @Description: com.weng.cloud.service8881.async.service
 */
@Service
@Slf4j
public class TestAsyncService {

    //异步方法的返回类型Future<>或void
    public CompletableFuture<String> busyMethod(String flag){
        this.doBusyMethod(flag);
        return CompletableFuture.completedFuture("【异步返回】"+flag);
    }

    //AdviceMode.PROXY这一步是失效的
    @Async
    public void doBusyMethod(String flag){
        log.error("执行开始-->{}",flag);
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.error("执行完成-->{}",flag);
    }
}
